package com.huaxin.hxmoduleworkorder.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxmoduleworkorder.common.enums.base.BaseCodeEnum;
import lombok.Getter;

/**
 * 工单状态枚举类
 */
@Getter
public enum InspectionOrderStatus implements BaseCodeEnum {
    PUBLISHED("published", "已发布"),
    IN_PROGRESS("in_progress", "执行中"),
    COMPLETED("completed", "已完成"),
    CANCELLED("cancelled", "已取消");

    @EnumValue
    private final String code;
    private final String displayName;

    InspectionOrderStatus(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static InspectionOrderStatus of(String code) {
        if (code == null) return null;
        for (InspectionOrderStatus s : values()) {
            if (s.getCode().equalsIgnoreCase(code)) return s;
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}
